<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	 public function __construct() {
        parent:: __construct();
        $this->load->helper("url");
        $this->load->library("pagination");
		$this->load->library('session');
    }

	public function reset()
	{
		$this->session->set_userdata("dm_id",FALSE);
	}
	 
	public function index()
	{	
		$this->load->helper('form');
		$tmp_mdl = $this->input->post('dm', TRUE);	
		if($tmp_mdl == "" & $this->session->userdata("dm_id")== FALSE)
		{
			$tmp_mdl = "welcome_model";
		}
		else
		{
			if($tmp_mdl == "")
			{
				$tmp_mdl = $this->session->userdata("dm_id") ;
			}
			else
			{
				if($tmp_mdl <> "" & $this->session->userdata("dm_id") <> $tmp_mdl)
				{
					$this->session->set_userdata("dm_id",$tmp_mdl) ;
				}
			}
		}
		
		$data["dm_id"] = $tmp_mdl;		
		$this->load->model($tmp_mdl,"mdl");
		
		$config = array();
        $config["base_url"] = base_url() . "index.php?/welcome/index/"  ;		
		$config["total_rows"] = $this->mdl->record_count();
        $config["per_page"] = 4;
        $config["uri_segment"] = 3;
		$config['full_tag_open'] = '<p>';
		$config['full_tag_close'] = '</p>';
		$this->pagination->initialize($config);
		$data["links"] = $this->pagination->create_links();
		
		$page = ($this->uri->segment(3))? (int)$this->uri->segment(3) : 0;		
		$limits = array($page,$config["per_page"]);		
		$data["tmp"] = $this->mdl->get_data($limits);

		$this->load->library('table');
		$this->table->set_heading($this->mdl->get_heading());		
		$data["tbl"] = $this->table->generate($data["tmp"]);

		$this->load->view('welcome_view',$data);	
		
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */